package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.entity.CheckVersionRespond;
import com.jiutong.meipengdai.http.model.interfaces.BaseBiz;
import com.jiutong.meipengdai.http.model.interfaces.CheckVersionBiz;
import com.jiutong.meipengdai.http.model.requests.CheckVersionRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 */

public class CheckVersionPresent {

    private final Context mContext;
    private final CheckVersionBiz mBiz;
    private final CheckVersionRequest versionRequest;

    public CheckVersionPresent(Context context, CheckVersionBiz biz) {
        this.mContext = context;
        this.mBiz = biz;
        this.versionRequest = new CheckVersionRequest();
    }

     public void checkVersion() {

        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<CheckVersionRespond>() {
            @Override
            public void onNext(CheckVersionRespond subjects) {
                mBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
         fieldsMap.put("appType", "AND");
         fieldsMap.put("currentVersion", mBiz.getCurrentVersion()+"");
        versionRequest.checkVersion(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }
}
